var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e;
} : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
}, app = getApp(), siteinfo = require("../../../siteinfo.js");

Page({
    data: {
        sign_up: [ {
            name: "姓名"
        }, {
            name: "手机号"
        } ],
        upload_img: [],
        select: !0
    },
    onLoad: function(o) {
        var i = this;
        app.setNavigationBarColor(this), console.log(o), i.setData({
            price: o.price,
            activity_id: o.activity_id,
            upload: o.upload
        }), console.log(o.activity_id), app.util.request({
            url: "entry/wxapp/Gethdbm",
            cachetime: "0",
            data: {
                activity_id: o.activity_id
            },
            success: function(e) {
                if (console.log("获取报名信息"), console.log(e), 0 == e.data.length) {
                    var t = i.data.sign_up;
                    if ("" != o.cus_name) (a = {}).name = o.cus_name, t.push(a);
                    i.setData({
                        sign_up: t
                    });
                } else {
                    var a;
                    t = e.data;
                    if ("" != o.cus_name) (a = {}).name = o.cus_name, t.push(a);
                    i.setData({
                        sign_up: t
                    });
                }
            }
        }), app.getUserInfo(function(e) {
            console.log(e), i.setData({
                user_id: e.id,
                openid: e.openid,
                uniacid: e.uniacid
            });
        }), i.refresh();
    },
    select: function(e) {
        this.setData({
            select: !this.data.select
        });
    },
    notice: function(e) {
        wx.navigateTo({
            url: "notice"
        });
    },
    refresh: function(e) {
        var t = wx.getStorageSync("tickets"), a = [];
        t.map(function(e) {
            var t = {};
            t.gm_num = e.num, t.money = e.money, t.bm_check = e.bm_check, t.tk_name = e.tk_name, 
            t.ticket_id = e.id, a.push(t);
        }), console.log(a), this.setData({
            tickets: t,
            ticket: a
        }), console.log(t);
    },
    uploadImg: function(e) {
        var a = this, o = a.data.upload_img;
        wx.chooseImage({
            count: 9 - o.length,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                console.log(e);
                var t = e.tempFilePaths;
                a.setData({
                    upload_img: o.concat(t)
                });
            }
        });
    },
    uploadimg: function(a) {
        var o = this, i = o.data.upload_img, n = a.i ? a.i : 0, c = a.success ? a.success : 0, s = a.fail ? a.fail : 0;
        wx.uploadFile({
            url: a.url,
            filePath: a.path[n],
            name: "upfile",
            formData: null,
            success: function(e) {
                "" != e.data ? (c++, i[n] = e.data, console.log("上传商家轮播图时候提交的图片数组", i)) : wx.showToast({
                    icon: "loading",
                    title: "请重试"
                });
            },
            fail: function(e) {
                s++, wx.showToast({
                    icon: "none",
                    title: "上传失败"
                });
            },
            complete: function() {
                if (++n == a.path.length) {
                    var e = o.data.sign_up;
                    i = i.join(",");
                    var t = {
                        name: "上传图片"
                    };
                    t.value = i, e = e.push(t), console.log("可以提交了"), console.log(e), o.place_order(), 
                    console.log("undefined" == typeof ticket ? "undefined" : _typeof(ticket)), wx.hideToast(), 
                    wx.hideLoading();
                } else a.i = n, a.success = c, a.fail = s, o.uploadimg(a);
            }
        });
    },
    cancel_img: function(e) {
        var t = this.data.upload_img, a = e.currentTarget.dataset.index;
        t.splice(a, 1), this.setData({
            upload_img: t
        });
    },
    formSubmit: function(e) {
        wx.getSetting({
          success: function (e) {
            if (1 != e.authSetting["scope.userInfo"]) {
              app.getUserInfo(function (e) {
                console.log(e), i.setData({
                  user_id: e.id,
                  openid: e.openid,
                  uniacid: e.uniacid
                });
              })
              return
            }
          },
          fail() {
            app.getUserInfo(function (e) {
              console.log(e), i.setData({
                user_id: e.id,
                openid: e.openid,
                uniacid: e.uniacid
              });
            })
            return
          }
        })
        var t = this, a = e.detail.formId, o = t.data.sign_up, i = e.detail.value, n = "";
        t.setData({
            formId: a
        });
        for (var c = 0; c < o.length; c++) o[c].value = i["name" + c], "" == o[c].value && (n = "请输入您的" + o[c].name);
        if ("" != n) wx.showModal({
            title: "温馨提示",
            content: n
        }); else {
            console.log("输入完全了"), t.setData({
                sign_up: o
            });
            t.data.ticket;
            var s = t.data.user_id, l = t.data.activity_id, u = t.data.price, d = t.data.openid;
            console.log("活动id为" + l), console.log("用户id为" + s), console.log("需要支付的金额为" + u), 
            console.log("用户的openid为" + d), console.log("这是报名信息"), console.log(o), console.log(void 0 === o ? "undefined" : _typeof(o)), 
            console.log("这是票券信息");
            var p = siteinfo.siteroot;
            1 == t.data.upload ? (t.uploadimg({
                url: p + "?i=" + t.data.uniacid + "&c=entry&a=wxapp&do=Upload&m=zh_gjhdbm",
                path: t.data.upload_img
            }), wx.showLoading({
                title: "开始上传"
            })) : t.place_order();
        }
    },
    place_order: function(e) {
        var o = this, i = o.data.formId, t = o.data.ticket, a = o.data.user_id, n = o.data.activity_id, c = o.data.price, s = o.data.openid, l = o.data.sign_up;
        c <= 0 ? app.util.request({
            url: "entry/wxapp/savebm",
            cachetime: "0",
            data: {
                activity_id: n,
                user_id: a,
                ticket: t,
                bm: l
            },
            success: function(e) {
                console.log("提交报名"), console.log(e);
                var t = e.data, a = wx.getStorageSync("userInfo").openid;
                app.util.request({
                    url: "entry/wxapp/Message1",
                    cachetime: "0",
                    data: {
                        form_id: i,
                        openid: a,
                        bm_id: t
                    },
                    success: function(e) {
                        console.log("发送模板消息"), console.log(e);
                    }
                }), wx.redirectTo({
                    url: "fill_success?price=" + o.data.price
                });
            }
        }) : app.util.request({
            url: "entry/wxapp/savebm",
            cachetime: "0",
            data: {
                activity_id: n,
                user_id: a,
                ticket: t,
                bm: l
            },
            success: function(e) {
                console.log("保存报名"), console.log(e);
                var a = e.data;
                app.util.request({
                    url: "entry/wxapp/Pay",
                    cachetime: "0",
                    data: {
                        openid: s,
                        money: c,
                        bm_id: a
                    },
                    success: function(e) {
                        wx.requestPayment({
                            timeStamp: e.data.timeStamp,
                            nonceStr: e.data.nonceStr,
                            package: e.data.package,
                            signType: e.data.signType,
                            paySign: e.data.paySign,
                            success: function(e) {
                                console.log("支付成功"), console.log(e);
                                var t = wx.getStorageSync("userInfo").openid;
                                app.util.request({
                                    url: "entry/wxapp/Message1",
                                    cachetime: "0",
                                    data: {
                                        form_id: i,
                                        openid: t,
                                        bm_id: a
                                    },
                                    success: function(e) {
                                        console.log("发送模板消息"), console.log(e);
                                    }
                                }), wx.redirectTo({
                                    url: "fill_success?price=" + o.data.price
                                });
                            },
                            fail: function(e) {
                                console.log("支付失败"), console.log(e), wx.showToast({
                                    title: "支付失败",
                                    duration: 1e3
                                });
                            }
                        });
                    }
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});